package com.service.machine;

import com.common.ErrorCodeEnum;
import com.common.emums.DataStatus;
import com.common.exception.BusinessException;
import com.common.utils.StringUtils;
import com.core.springSecurity.common.SecurityUtils;

import com.dao.primary.machine.MachineInfoMapper;
import com.model.domain.machine.GetMachineInfoDO;
import com.model.pojo.machine.MachineInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.github.pagehelper.PageHelper;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;



/**
 * @Author: zql
 * @Description: 农机信息服务
 * @Data: 2023-08-26
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class MachineInfoService {
    private final MachineInfoMapper machineInfoMapper;

    public List<MachineInfo> getPageList(GetMachineInfoDO getMachineInfoDO){
        PageHelper.clearPage();
        PageHelper.startPage(getMachineInfoDO.getPage(),getMachineInfoDO.getPageSize(),getMachineInfoDO.getSortRow()+getMachineInfoDO.getSortOrder());
        return machineInfoMapper.selectList(getMachineInfoDO);
    }

    public List<MachineInfo> getAllList(GetMachineInfoDO getMachineInfoDO){
        PageHelper.clearPage();
        PageHelper.orderBy(getMachineInfoDO.getSortRow()+getMachineInfoDO.getSortOrder());
        return machineInfoMapper.selectList(getMachineInfoDO);
    }

    public MachineInfo getById(Long id){
        return machineInfoMapper.selectByPrimaryKey(id);
    }

    public int save(MachineInfo info){
        info.setCreateTime(new Date());
        return machineInfoMapper.insertSelective(info);
    }
    public int update(MachineInfo info){
        info.setUpdateTime(new Date());
        return machineInfoMapper.updateByPrimaryKeySelective(info);
    }

    public int delete(MachineInfo info){
        info.setIsDelete(-1);
        return machineInfoMapper.updateByPrimaryKeySelective(info);
    }

    public MachineInfo getByTerminalNum(String terminalNum){
        return machineInfoMapper.selectByTerminalNum(terminalNum);
    }
}
